home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_2 / issue_07 / spriteplot / spritenote < prev    next >
Encoding:
Text File  |  1989-03-16  |  5.2 KB  |  151 lines

  1. 06601010101800
  2. 1
  3. 2#
  4. F0110030
  5. 9[........................................................]001
  6. ŴANIMATEDSPRITES€
  7.  
  8. ByIanSmith
  9.  
  10. There have been many articles relating to the use of Sprites onthe
  11. Archimedes.ThesehavecoveredtheuseofPLOT&ED,X,Ytodisplaya
  12. Spriteinitsdefinedcoloursatpoint(X,Y)andtheuseofaMaskto
  13. allowabackgroundtoappearthroughthe'unused'partsofasprite.
  14. TheyhavealsoshowntheuseofExclusiveORplottingusingGCOL11,0to
  15. allowthespritetobemovedoveranycolouredbackground.
  16.  
  17. TheEORsolutiontothislastproblem,ofmovingamulti-colouredsprite
  18. overamulticolouredbackground,worksBUTunlessagreatdealof
  19. thoughtisgiventopaletteselectionthespriteDOESNOTretainits
  20. definedcolourduringmovement.
  21.  
  22. Manygameswillrequirethefacilitytodefineaspriteinspecified
  23. colours,withamask,andtomoveitSTILLretainingthosecolours
  24. ratherthanthoseproducedbyEOR.
  25.  
  26. AsolutionistousethestandardMove/Display/EraseinaloopBUTNOT
  27. touseEOR.ThefollowingAlgorithmdoesthis:
  28.  
  29.  
  30.  1   Definethesprite'MySprite'WITHaMASK(usingSEDITonthe
  31.      WelcomeDisk).
  32.  
  33.  2  Determinethesizeof'MySprite'.
  34.      ThismaybeknownBUTaSYScalldoesitforyou.
  35.  
  36. LOOP
  37.  
  38.  3   Determinethepositionwhere'MySprite'istobeplotted.
  39.      
  40.  4   GRABasprite'Temp'fromthescreenatthispositionthe
  41.      samesizeas'MySprite'.
  42.  
  43.  5   PLOT'MySprite'withthemask.
  44.  
  45. 6   PLOTthegrabbedsprite'Temp'toERASE'Mysprite'.
  46.  
  47. ENDLOOP
  48.  
  49. Thefollowingprogramdemonstratesthis:
  50.    10 REM > SpritePlot
  51.    20 REM  Copyright Ian Smith
  52.    30 REM  March 1989
  53.    40
  54.    50 REM An example program to show the use of sprites moving
  55.    60 REM across a multi coloured background by grabbing an area
  56.    70 REM of screen as a sprite and then using it to overwrite the
  57.    80 REM moving sprite.
  58.    90
  59.   100 MODE 15          : REM Works in others modes
  60.   110 T$="Temp"        : REM Will be the sprite grabbed from screen
  61.   120 M$="MySprite"    : REM A masked sprite created with SEDIT
  62.   130 *SLOAD !Sprites
  63.   140
  64.   150 SYS &2E,40,,T$ TO ,,,W,H   : REM Find size of sprite to grab
  65.   160                            : REM W)idth and H)eight
  66.   170 PROCDrawBackground         : REM Draw a Multicoloured background
  67.   180 PROCTitle                  : REM and put titles on
  68.   190
  69.   200 REPEAT
  70.   210   REM ****** MOVE ******
  71.   220   MOUSE X,Y,B
  72.   230   SYS &2E,16,,T$,1,X,Y,X+W*2,Y+H*4   : REM Grab sprite from screen
  73.   240
  74.   250   OSCLI("SCHOOSE " + M$ )  : REM Select original sprite
  75.   260
  76.   270   REM ****** DISPLAY ******
  77.   280   GCOL 8,0                 : REM Now plot it with its mask
  78.   290   PLOT &ED, X,Y            : REM at the mouse position
  79.   300   PLOT &ED,900,800         : REM and display it in rectangle
  80.   310
  81.   320   WAIT:WAIT                : REM Synchronise output
  82.   330
  83.   340   OSCLI("SCHOOSE " + T$)   : REM Now plot the grabbed sprite
  84.   350
  85.   360   REM ****** ERASE ******
  86.   370   GCOL 0,0
  87.   380   PLOT &ED,X,Y             : REM at the same place
  88.   390   PLOT &ED,1000,800        : REM and in its rectangle
  89.   400 UNTIL B=7                  : REM 3 buttons terminates
  90.   410 END
  91.   420
  92.   430 DEF PROCDrawBackground
  93.   440   GCOL 3 : RECTANGLE FILL 0,0,300,300      : REM Just a couple of
  94.   450   GCOL 4 : RECTANGLE FILL 50,50,50,50      : REM rectangles and
  95.   460   GCOL 12: CIRCLE FILL 800,400,200         : REM circle
  96.   470   GCOL 5 : CIRCLE FILL 600,300,100
  97.   480   OSCLI("SCHOOSE " +  M$)
  98.   490   PLOT &ED,75,90                           : REM and the sprite
  99.   500 ENDPROC
  100.   510
  101.   520 DEF PROCTitle
  102.   530   GCOL 1
  103.   540   RECTANGLE 900-2,800-4,W*2+4,H*4+8   : REM Draw rectangles
  104.   550   RECTANGLE 1000-2,800-4,W*2+4,H*4+8  : REM in which sprires
  105.   560   PRINT TAB(53,2);"S P R I T E S"     : REM are displayed
  106.   570   PRINT TAB(52,3);"original grabbed"
  107.   580   PRINT TAB(0,1);"SPRITE DEMONSTRATION : use mouse to move sprite"
  108.   590 ENDPROC
  109.  
  110.  
  111. €Commentsontheprogram:
  112.  
  113. PROCDrawBackgoundsetsupabackgroundtomoveover.
  114. PROCTitleSimplyputsTextandacoupleofrectanglesonthescreen
  115.  
  116. 150UsesaSYScalltofindtheWidthandHeightof'MySprite'
  117. Thisisneededsothattherightsize'Temp'canbegrabbed.
  118.    (SeeProgrammersReferenceManualpp429,433)
  119. 
  120. 230GrabsthespritefromthescreenusingaSYScall.
  121. Notethe*2and*4tocompensateforscreenMODE15
  122. You'llneedtochangethisforotherresolutionmodes.
  123.  
  124. 250Selects'MySprite'
  125.  
  126. 280SelectstheMaskPlotoptionGCOL8.
  127.  
  128. 290PlotsthespriteattheMouseselectedpoint
  129.  
  130. 300Plotsthespriteinarectangletoshowitsoriginalcolours.
  131.  
  132. 340Selects'Temp'
  133.  
  134. 380Plots'Temp'effectivelyerasing'MySprite'
  135.  
  136. 390Plots'Temp'initsrectangle.
  137.  
  138. Theeffectof390hasaninterestingside-effect.
  139. Whenyouruntheprogrammovethespriteovertherectangle!Seewhat
  140. happens!
  141.  
  142. Theprogram'SpritePlot'andSpriteFile'!Sprites'areonthismonth's
  143. diskBUTyoucanusetheprogrambykeyingitinANDALSOCREATINGA
  144. MASKEDSPRITEINMODE15USINGSEDITSAVEDAS!SPRITES.
  145.  
  146. TheprogramcanobviouslybemodifiedtoruninotherModes.
  147. TheflickerontheSpritecanberemovedbymodifyingtheprogramto
  148. plotONLYifthemousehasbeenmoved.
  149.  
  150.